package cn.itsource;

import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
// @EnableEurekaClient 标记为客户端
// @EnableDiscoveryClient
@EnableCircuitBreaker  //开启Hystrix熔断
public class OrderApp {

    //声明一个restTemplate的bean
    @Bean
    @LoadBalanced // 开启RestTemplate负载均衡能力【默认为轮询】 使用ribbon需要修改URL为应用名
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    // 负载均衡算法 随机选择 指定了算法后就不执行默认的
    @Bean
    public RandomRule randomRule(){
        return new RandomRule();
    }
    public static void main(String[] args) {
        SpringApplication.run(OrderApp.class);
    }
}